package game.editer.view;

import game.editer.ui.Config;
import hx.display.Label;
import hx.display.Graphics;
import hx.events.MouseEvent;
import hx.layout.AnchorLayout;
import hx.layout.AnchorLayoutData;
import hx.display.MovieClip;
import hx.display.Box;

/**
 * 特效预览显示对象
 */
class EffectPreviewDisplay extends Box {
	private var __frame:Graphics;

	public var id:String;

	public function new(id:String):Void {
		super();
		this.id = id;

		this.width = this.height = 120;
		var atlas = EditerStage.roleAssets.getAtlas(id);
		var mc = new MovieClip(atlas.getBitmapDatasByName());
		this.addChild(mc);
		mc.play();
		mc.scaleX = mc.scaleY = Math.min(120 / mc.width, 120 / mc.height);
		mc.layoutData = AnchorLayoutData.center(0, 0);
		this.layout = new AnchorLayout();

		__frame = new Graphics();
		__frame.beginLineStyle(0xff0000, 2);
		__frame.lineTo(120, 0);
		__frame.lineTo(120, 120);
		__frame.lineTo(0, 120);
		__frame.lineTo(0, 0);
		this.addChild(__frame);
		__frame.visible = false;

		this.mouseChildren = false;

		var label = new Label(id, Config.COMMON_TEXT_FORMAT);
		this.addChild(label);
		label.width = 120;
		label.x = label.y = 3;
	}

	public function setSelected(bool:Bool):Void {
		this.__frame.visible = bool;
	}

	public function isSelected():Bool {
		return this.__frame.visible;
	}
}
